package com.westcom.vulb.logic;

import java.io.UnsupportedEncodingException;

import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.westcom.vulb.network.http.VulbHttp;
import com.westcom.vulb.protocal.http.Response;

public class comment extends BasicLogic
{
	private static String CreateComment_url = base_url+"web/new_comment";
	private static String GetCommentList_url =base_url+"web/comment_list";
	private static String Valuat_url = base_url+"web/comment_valuation";
	private static String GetGoodCommentList_url = base_url+"web/comment_good_member_list";
	private static String DeleteComment_url = base_url + "web/delete_comment";

	public static comment getInstanse()
	{
		return new comment();
	}
	public Response CreateComment(String sessionId,int cardId,int toCommentId,String content)
	{
		String tmp = null;
		try 
		{
			tmp = new String(content.getBytes(),"ISO-8859-1");
		} catch (UnsupportedEncodingException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		JSONObject j = new JSONObject();
		try 
		{
			j.put("cardId", cardId);
			j.put("toCommentId", toCommentId);
			j.put("content", tmp);
		} catch (JSONException e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		MultipartEntityBuilder builder = MultipartEntityBuilder.create();
		builder.addTextBody("params", j.toString());
		builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
		Response response = VulbHttp.post(CreateComment_url,buildHeader(sessionId),builder.build());
		return response;		  
	}
	public Response GetCommentList(String sessionId,JSONArray cards)
	{
		JSONObject j = new JSONObject();
		try 
		{
			j.put("cards", cards);
		} catch (JSONException e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		MultipartEntityBuilder builder = MultipartEntityBuilder.create();
		builder.addTextBody("params", j.toString());
		builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
		Response response = VulbHttp.post(GetCommentList_url,buildHeader(sessionId),builder.build());
		return response;

	}
	public Response Valuat(String sessionId,int commentId,int valuation )
	{
		JSONObject j = new JSONObject();
		try 
		{
			j.put("commentId",commentId);
			j.put("valuation",""+valuation);
		} catch (JSONException e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		MultipartEntityBuilder builder = MultipartEntityBuilder.create();
		builder.addTextBody("params", j.toString());
		builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
		Response response = VulbHttp.post(Valuat_url,buildHeader(sessionId),builder.build());
		return response;
	}
	public Response GetGoodCommentList(String sessionId,int commentId)
	{
		JSONObject j = new JSONObject();
		try 
		{
			j.put("commentId",commentId);
		} catch (JSONException e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		MultipartEntityBuilder builder = MultipartEntityBuilder.create();
		builder.addTextBody("params", j.toString());
		builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
		Response response = VulbHttp.post(GetGoodCommentList_url,buildHeader(sessionId),builder.build());
		return response;
	}
	public Response DeleteComment(String sessionId,int commentId)
	{
		JSONObject j = new JSONObject();
		try 
		{
			j.put("commentId",commentId);
		} catch (JSONException e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		MultipartEntityBuilder builder = MultipartEntityBuilder.create();
		builder.addTextBody("params", j.toString());
		builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
		Response response = VulbHttp.post(DeleteComment_url,buildHeader(sessionId),builder.build());
		return response;
	}
}
